public class FindMinimumInRotatedSortedArray {
    public int findMin1(int[] nums) {
        int n = nums.length;
        int left = 0, right = n - 1;
        while(left < right) {
            int mid = left + ((right - left) >> 1);
            if(nums[mid] <= nums[n - 1]) {
                right = mid;
            }else {
                // nums[mid] > nums[n - 1]
                left = mid + 1;
            }
        }
        return nums[left];
    }

    public int findMin(int[] nums) {
        int n = nums.length;
        int left = 0, right = n - 1;
        while(left < right) {
            int mid = left + ((right - left) >> 1);
            if(nums[mid] >= nums[0]) {
                left = mid + 1;
            }else {
                // nums[mid] < nums[0]
                right = mid;
            }
        }
        // 边界处理
        if(left == n - 1 && nums[n - 1] > nums[0]) {
            return nums[0];
        }
        return nums[left];
    }
}
